<p><!DOCTYPE html>
<html>
<head>
	<title>http</title>

	<script type="text/javascript" src="angular-1.4.6/angular.min.js"></script>


</head>
<body>

<div  ng-controller="ctrl" ng-app="app">
    <!--可以使用http来引入html,但是不能编译-->

    <div ng-bind-html="content | trustHtml"></div>


    <!--可以引入html，也能编译-->
     <dy-compile html="{{content}}">

     </dy-compile>

</div>






   
</body>


<script type="text/javascript">
           var app = angular.module('app', []);
           
           app.controller('ctrl', function($scope, $http) {
            $http.get("demo.html")
             .success(function (response) {
                console.info(response);
                //这样的话，再页面上输出的就是字符串的html代码，显然不是我们想要的
                $scope.content = response;
                 $scope.name = "huanghaoming";
               
            });
          });

           //使用过滤器，把score转义成html格式
          app.filter('trustHtml', function ($sce) {
               return function (input) {
                     return $sce.trustAsHtml(input);
                }
          });






           app.directive("dyCompile", ["$compile", function($compile) {
             return {
            replace: true,
            restrict: 'EA',
            link: function(scope, elm, iAttrs) {

                var DUMMY_SCOPE = {
                        $destroy: angular.noop
                    },
                    root = elm,
                    childScope,
                    destroyChildScope = function() {
                        (childScope || DUMMY_SCOPE).$destroy();
                    };

                iAttrs.$observe("html", function(html) {

                    if (html) {
                        destroyChildScope();
                        childScope = scope.$new(false);
                        var content = $compile(html)(childScope);
                        root.replaceWith(content);
                        root = content;
                    }

                    scope.$on("$destroy", destroyChildScope);
                });
            }
        };
    }]);




</script>


</html>